package com.nju.edu.erp.service.finance;

import com.nju.edu.erp.dao.BusinessHistoryDao;
import com.nju.edu.erp.model.po.PurchaseReturnsSheetPO;
import com.nju.edu.erp.model.po.PurchaseSheetPO;
import com.nju.edu.erp.model.po.SaleReturnsSheetPO;
import com.nju.edu.erp.model.po.SaleSheetPO;
import com.nju.edu.erp.model.vo.GetBusinessHistoryVO;
import com.nju.edu.erp.model.vo.Sale.SaleSheetVO;
import com.nju.edu.erp.model.vo.purchase.PurchaseSheetVO;
import com.nju.edu.erp.model.vo.purchaseReturns.PurchaseReturnsSheetVO;
import com.nju.edu.erp.model.vo.saleReturns.SaleReturnsSheetVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class BusinessHistoryServiceImpl implements BusinessHistoryService {
    private final BusinessHistoryDao businessHistoryDao;
    @Autowired
    BusinessHistoryServiceImpl(BusinessHistoryDao businessHistoryDao){
        this.businessHistoryDao=businessHistoryDao;
    }

    @Override
    public List<SaleSheetVO> getSaleSheet(GetBusinessHistoryVO getBusinessHistoryVO) {
        this.stub(getBusinessHistoryVO);
        List<SaleSheetVO> saleSheetVOS=new ArrayList<>();
        List<SaleSheetPO> saleSheetPOS=businessHistoryDao.getSaleSheet(
                getBusinessHistoryVO.getBeginDate(),
                getBusinessHistoryVO.getEndDate(),
                getBusinessHistoryVO.getCName(),
                getBusinessHistoryVO.getOperator());
        for (SaleSheetPO spo:saleSheetPOS) {
            SaleSheetVO saleSheetVO=new SaleSheetVO();
            BeanUtils.copyProperties(spo,saleSheetVO);
            saleSheetVOS.add(saleSheetVO);
        }
        return saleSheetVOS;
    }

    @Override
    public List<SaleReturnsSheetVO> getSaleReturnsSheet(GetBusinessHistoryVO getBusinessHistoryVO) {
        this.stub(getBusinessHistoryVO);
        List<SaleReturnsSheetVO> saleReturnsSheetVOS=new ArrayList<>();
        List<SaleReturnsSheetPO> saleReturnsSheetPOS=businessHistoryDao.getSaleReturnsSheet(
                getBusinessHistoryVO.getBeginDate(),
                getBusinessHistoryVO.getEndDate(),
                getBusinessHistoryVO.getCName(),
                getBusinessHistoryVO.getOperator());
        for (SaleReturnsSheetPO srpo:saleReturnsSheetPOS) {
            SaleReturnsSheetVO saleReturnsSheetVO=new SaleReturnsSheetVO();
            BeanUtils.copyProperties(srpo,saleReturnsSheetVO);
            saleReturnsSheetVOS.add(saleReturnsSheetVO);
        }
        return saleReturnsSheetVOS;
    }

    @Override
    public List<PurchaseSheetVO> getPurchaseSheet(GetBusinessHistoryVO getBusinessHistoryVO) {
        this.stub(getBusinessHistoryVO);
        List<PurchaseSheetVO> purchaseSheetVOS=new ArrayList<>();
        List<PurchaseSheetPO> purchaseSheetPOS=businessHistoryDao.getPurchaseSheet(
                getBusinessHistoryVO.getBeginDate(),
                getBusinessHistoryVO.getEndDate(),
                getBusinessHistoryVO.getCName(),
                getBusinessHistoryVO.getOperator());
        for (PurchaseSheetPO pspo:purchaseSheetPOS) {
            PurchaseSheetVO purchaseSheetVO=new PurchaseSheetVO();
            BeanUtils.copyProperties(pspo,purchaseSheetVO);
            purchaseSheetVOS.add(purchaseSheetVO);
        }
        return purchaseSheetVOS;
    }

    @Override
    public List<PurchaseReturnsSheetVO> getPurchaseReturnsSheet(GetBusinessHistoryVO getBusinessHistoryVO) {
        this.stub(getBusinessHistoryVO);
        List<PurchaseReturnsSheetVO> purchaseReturnsSheetVOS=new ArrayList<>();
        List<PurchaseReturnsSheetPO> purchaseReturnsSheetPOS=businessHistoryDao.getPurchaseReturnsSheet(
                getBusinessHistoryVO.getBeginDate(),
                getBusinessHistoryVO.getEndDate(),
                getBusinessHistoryVO.getCName(),
                getBusinessHistoryVO.getOperator());
        for (PurchaseReturnsSheetPO p:purchaseReturnsSheetPOS) {
            PurchaseReturnsSheetVO purchaseReturnsSheetVO=new PurchaseReturnsSheetVO();
            BeanUtils.copyProperties(p,purchaseReturnsSheetVO);
            purchaseReturnsSheetVOS.add(purchaseReturnsSheetVO);
        }
        return purchaseReturnsSheetVOS;
    }
    private void stub(GetBusinessHistoryVO getBusinessHistoryVO){
    }

}
